package com.lqs.dataservice.Service;


import com.lqs.dataservice.constants.MessageConstants;
import com.lqs.dataservice.dao.RepairDao;
import com.lqs.dataservice.entity.Repair;
import com.nip.db.mongodb.utils.tips.Response;
import com.nip.db.mongodb.utils.tips.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * UserService
 *
 * @author < a href=" ">lqs</ a>
 * @version v1.0.01
 * @date 2019-12-27 16:47
 */
@Service
public class RepairService {
    @Autowired
    RepairDao repairDao;

    public Repair findRepairById(String id) {
        return repairDao.findById(id).orElse(null);
    }

    public List<Repair> findAllByRepState(String repState){
        return repairDao.findAllByRepState(repState);
    }

    public Response saveRepair(Repair entity) {
        try {
//            if(StrUtil.isEmpty(entity.getId())){
//                entity.setRepState("0");
//            }
            repairDao.save(entity);
            return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
        } catch (Exception e) {
            return new Response(ResponseCode.CODE_202, e.getMessage());
        }
    }

    public Response deleteRepairById(String id) {
        try {
            repairDao.deleteById(id);
            return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
        } catch (Exception e) {
            return new Response(ResponseCode.CODE_202, e.getMessage());
        }
    }

//    public Response passRepair(Repair entity,String repEndId){
//            try {
//            entity.setRepEndId(repEndId);
//            entity.setRepImgEnd();
//            entity.setRepEndTime();
//            entity.setRepRemarkEnd();
//            entity.setMaterialRecordId();
//        }
//    }
}
